//
//  StaffStatePicker.m
//  APJ HRadar
//
//  Created by Luna Gao on 14-3-29.
//  Copyright (c) 2014年 APJ. All rights reserved.
//

#import "StaffStatePicker.h"
#import "HRStore.h"
#import "Dept.h"

@interface StaffStatePicker ()

@end

@implementation StaffStatePicker
@synthesize selectedStateName, popView;

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //dataSource = [[HRStore sharedStore] allDept];
    dataSource = [[NSArray alloc] initWithObjects:@"Recruitment",@"Probation",@"Intern",@"Hire",@"Resign",@"Dismiss",@"Retirement", nil];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [dataSource count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"StateCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                      reuseIdentifier:CellIdentifier];
    }
    
    NSString *d = (NSString *)[dataSource objectAtIndex:[indexPath row]];
    [[cell textLabel] setText:d];
    //[cell setIndentationLevel:[d deptId]];
    [cell setIndentationWidth:0.0];
    
    if (d == selectedStateName) {
        [cell setAccessoryType:UITableViewCellAccessoryCheckmark];
    }
    
    
    return cell;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    //selectedStateId = (int)[cell indentationLevel];
    selectedStateName = cell.textLabel.text;
    [[popView delegate] popoverControllerDidDismissPopover:popView];
}

@end
